//
//  AudioManager.m
//  Ikinloop-demo
//
//  Created by Li Shen on 2021/4/16.
//  Copyright © 2021 lyh. All rights reserved.
//

#import <AVFoundation/AVFoundation.h>
#import "IKAudioManager.h"


@interface IKAudioManager ()


@property (nonatomic,strong)AVAudioPlayer *duPlayer;

@property (nonatomic,strong)AVAudioPlayer *startPlayer;

@property (nonatomic,strong)AVAudioPlayer *shakePlayer;

@property (nonatomic,strong)AVAudioPlayer *unusablePlayer;

@property (nonatomic,strong)AVAudioPlayer *stopPlayer;

@property (nonatomic,strong)AVAudioPlayer *noBlePlayer;

@property (nonatomic,strong)AVAudioPlayer *foundNewDevPlayer;

@property (nonatomic,strong)AVAudioPlayer *lowpowerPlayer;

@property (nonatomic,strong)AVAudioPlayer *handTipPlayer;

@property (nonatomic,strong)AVAudioPlayer *pressBtnPlayer;

@property (nonatomic,strong)AVAudioPlayer *bindSuccessPlayer;

@end
@implementation IKAudioManager

- (void)playStart{
    [self stopAllVoice];
    [self.startPlayer play];
}

- (void)playStop{
    [self stopAllVoice];
    [self.stopPlayer play];
}

- (void)playShake{
    [self stopAllVoice];
    [self.shakePlayer play];
}

- (void)playNoBle{
    [self stopAllVoice];
    [self.noBlePlayer play];
}

- (void)playUnusable{
    [self stopAllVoice];
    [self.unusablePlayer play];
}

- (void)playHandTip{
    [self stopAllVoice];
    [self.handTipPlayer play];
}

- (void)playLowPower{
    [self stopAllVoice];
    [self.lowpowerPlayer play];
}

- (void)playPressBtn{
    [self stopAllVoice];
    [self.pressBtnPlayer play];
}

- (void)playerBindSuccess{
    [self stopAllVoice];
    [self.bindSuccessPlayer play];
}

- (void)playerFoundNewDev{
    [self stopAllVoice];
    [self.foundNewDevPlayer play];
}

- (void)stopAllVoice{
    if(_stopPlayer != NULL){
        [_stopPlayer stop];
    }
    if(_stopPlayer != NULL){
        [_stopPlayer stop];
    }
    if(_shakePlayer != NULL){
        [_shakePlayer stop];
    }
    if(_noBlePlayer != NULL){
        [_noBlePlayer stop];
    }
    if(_unusablePlayer != NULL){
        [_unusablePlayer stop];
    }
    if(_handTipPlayer != NULL){
        [_handTipPlayer stop];
    }
    if(_lowpowerPlayer != NULL){
        [_lowpowerPlayer stop];
    }
    if(_pressBtnPlayer != NULL){
        [_pressBtnPlayer stop];
    }
    if(_bindSuccessPlayer != NULL){
        [_bindSuccessPlayer stop];
    }
    if(_foundNewDevPlayer != NULL){
        [_foundNewDevPlayer stop];
    }
}

- (AVAudioPlayer *)pressBtnPlayer
{
    if (!_pressBtnPlayer)
    {
        _pressBtnPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ikinloop_press_power_btn_zh" ofType:@"mp3"]] error:nil];
    }
    return _pressBtnPlayer;
}

- (AVAudioPlayer *)handTipPlayer
{
    if (!_handTipPlayer)
    {
        _handTipPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ikinloop_touch_metal_zh" ofType:@"mp3"]] error:nil];
    }
    return _handTipPlayer;
}

- (AVAudioPlayer *)startPlayer
{
    if (!_startPlayer)
    {
        _startPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ikinloop_start_record" ofType:@"wav"]] error:nil];
    }
    return _startPlayer;
}

/**
 信号干扰大，不可用
 
 @return return value description
 */
-(AVAudioPlayer *)unusablePlayer
{
    if (!_unusablePlayer)
    {
        NSString *str = @"ikinloop_nosie_big_test_agian_zh";
        _unusablePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:str ofType:@"mp3"]] error:nil];
    }
    return _unusablePlayer;
}

/**
 抖动
 
 @return return value description
 */
-(AVAudioPlayer *)shakePlayer
{
    if (!_shakePlayer)
    {
        NSString *str = @"ikinloop_noise_body_zh";
        _shakePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:str ofType:@"mp3"]] error:nil];
    }
    return _shakePlayer;
}

/**
 电量低
 */
-(AVAudioPlayer *)lowpowerPlayer
{
    if (!_lowpowerPlayer)
    {
        NSString *str = @"ikinloop_lowpower_zh";
        _lowpowerPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:str ofType:@"mp3"]] error:nil];
    }
    return _lowpowerPlayer;
}

/**
 请打开蓝牙
 
 @return return value description
 */
-(AVAudioPlayer *)noBlePlayer
{
    if (!_noBlePlayer)
    {
        NSString *str = @"ikinloop_open_ble_zh";
        _noBlePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:str ofType:@"mp3"]] error:nil];
    }
    return _noBlePlayer;
}

- (AVAudioPlayer *)stopPlayer
{
    if (!_stopPlayer)
    {
        _stopPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ikinloop_stop_record" ofType:@"wav"]] error:nil];
    }
    return _stopPlayer;
}

- (AVAudioPlayer *)foundNewDevPlayer
{
    if (_foundNewDevPlayer == nil) {
        NSString *str = @"ikinloop_found_new_device_zh";
        _foundNewDevPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:str ofType:@"mp3"]] error:nil];
    }
    return _foundNewDevPlayer;
}

- (AVAudioPlayer *)bindSuccessPlayer
{
    if (_bindSuccessPlayer == nil) {
        _bindSuccessPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ikinloop_bind_device_success_zh" ofType:@"mp3"]] error:nil];
    }
    return _bindSuccessPlayer;
}

@end
